package cn.wolfcode.service.impl;

import cn.wolfcode.aspect.Mylog;
import cn.wolfcode.domain.Emp;
import cn.wolfcode.domain.PageResult;
import cn.wolfcode.mapper.EmpMapper;
import cn.wolfcode.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    @Override
    public PageResult query(int page, int pageSize, String name, Integer gender, Date begin, Date end) {

        PageHelper.startPage(page,pageSize);
        List<Emp> emps =empMapper.list(name,gender,begin,end);
        Page<Emp> p=(Page<Emp>) emps;

        return new PageResult(p.getTotal(),p.getResult());
    }

    @Override
    @Mylog
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }
    @Override
    @Mylog
    public void save(Emp emp) {
        emp.setCreateTime(new Date());
        emp.setUpdateTime(new Date());
        System.out.println("接收的入职时间：" + emp.getHiredate());
        empMapper.save(emp);
    }
    @Override
    public Emp selById(Long id) {
        return empMapper.selById(id);
    }

    @Override
    @Mylog
    public void update(Emp emp) {
        emp.setUpdateTime(new Date());
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {

        return empMapper.login(emp);
    }
}
